package com.mjawor.lpgroovy.vars

class VarImpl<T> implements Var<T> {

	private String id
	private Number ub
	private Number lb
	private T value
    private Class type

	VarImpl(String id) {
		this.id = id
	}

	VarImpl(String id, value) {
        this.id = id
		this.value = value
	}

    @Override
    Var negative() {
        Var result = clone()
        result.value = - result.value
        return result
    }

    @Override
	T getValue() {
		return value
	}

    @Override
	Var setValue(T val) {
		this.value = val
		return this
	}

    @Override
	VarImpl lb(Number lb) {
		this.lb = lb
		return this
	}

    @Override
	VarImpl ub(Number ub) {
		this.ub = ub
		return this
	}

    @Override
	Number lb() {
		return lb
	}

    @Override
	Number ub() {
		return ub
	}

    @Override
	String toString() {
		if(value == null)
			return id
		else
			return value
	}

    @Override
    String getId() {
        return id
    }

    @Override
    Class getType() {
		return Integer
	}

    @Override
    Object clone() {
        def result = new VarImpl<T>(id, value)
        result.ub(ub()).lb(lb())
        result.type = type
        result.value = value
        return result
    }
}
